﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonMedicalVms
{
    public partial class SysPersonMedicalListVm : BasePagedListVM<SysPersonMedicalView, SysPersonMedicalSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonMedicalView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonMedicalView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.PersonMedicalBatcheName),
                this.MakeGridHeader(x => x.Result),
                this.MakeGridHeader(x => x.MedicalReportId).SetFormat(MedicalReportIdFormat),
                this.MakeGridHeaderAction(width: 200)
            };
        }
        private List<ColumnFormatInfo> MedicalReportIdFormat(SysPersonMedicalView entity, object val)
        {
            return new List<ColumnFormatInfo>
            {
                ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button,entity.MedicalReportId),
                ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button,entity.MedicalReportId,640,480),
            };
        }


        public override IOrderedQueryable<SysPersonMedicalView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonMedical>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckEqual(Searcher.PersonMedicalBatcheId, x=>x.PersonMedicalBatcheId)
                .CheckContain(Searcher.Result, x=>x.Result)
                .Select(x => new SysPersonMedicalView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    PersonMedicalBatcheName = x.PersonMedicalBatche.BatchName,
                    Result = x.Result,
                    MedicalReportId = x.MedicalReportId,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysPersonMedicalView : SysPersonMedical{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }
        [Display(Name = "批次名称")]
        public String PersonMedicalBatcheName { get; set; }

    }
}
